package com.zzy.utils;


import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

public class TestConnect {
    // 测试连接

    public static void main(String[] args) {
        testConnect();
    }

    public static void testConnect(){
        HttpHost httpHost = new HttpHost("192.168.15.128", 9200,"http");
        RestClientBuilder rb = RestClient.builder(httpHost) ;
        RestHighLevelClient client = new  RestHighLevelClient(rb);

        try {
            System.out.println("打开了 elasticsearch 链接。");
            Object o = client.getLowLevelClient();
            System.out.println(o);
            client.close();//关闭链接
            System.out.println("关闭了 elasticsearch 链接。");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
